import { request } from '@/utils/api'; 

export interface UpdateCoordinateParams {
  coordinate: []; 
}

export interface UpdateCoordinateResponse {
  success: boolean;  
  type: string;      
  message: string; 
}

interface ErrorResponse {
  error: string; 
}

type CoordinateResponse = UpdateCoordinateResponse | ErrorResponse;

// 更新坐标的异步函数
export async function updateCoordinate(imageId: number,params: UpdateCoordinateParams): Promise<CoordinateResponse> {
  try {
    const response = await request({
      url: `/pdf/coordinate/${imageId}`,
      method: 'post',                   
      data: params                     
    });

    if (response.status === 200) {
      return response.data as UpdateCoordinateResponse; 
    } else {
      return {
        error: '请求失败，状态码：' + response.status 
      } as ErrorResponse;
    }
  } catch (error: any) {
    const errorMessage = error.response?.data?.error || (error as Error).message; 
    return {
      error: errorMessage 
    } as ErrorResponse;
  }
}